
* DID ESTIMATES OF SHARES OF INMOVERS


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* GENERATE THE TREATMENT (AND CONTROL) GROUP 


cap rm "$mypathRR/Results/appendixtables/B5.2_appendixtable.xls"
cap rm "$mypathRR/Results/appendixtables/B5.2_appendixtable.txt"


local b " 60 55 "
local t " 80 75 "
local n : word count `b'

forvalues i = 1/`n' {
local x : word `i' of `b'
local y : word `i' of `t'
cap drop treat_i
gen treat_i=.
replace treat_i=0 if ctrl_ir_`x'_`y'==1
replace treat_i=1 if taxinc_thre2==1
label var treat_i "Income tax treatment"


preserve
sort persid zuzugjahre year
keep if freq==1
drop if year>2007
drop if zuzugjahre>2007

collapse (count) Inmovers=persid (mean) avgtt=avgt_stek_taxable (mean) avgtg=avgt_stek_gross (mean) mtr=mtr_total (mean) residents , by(zuzugjahre treat_i)
gen weight=Inmovers

xtset treat_i zuzugjahre
tsfill, full
replace Inmovers=0 if Inmovers==.


replace Inmovers=Inmovers/residents*100
label var Inmovers "Share of taxpayers"
label var avgtt "Average tax rate on taxable income"
label var avgtg "Average tax rate on gross income"
label var mtr "Marginal tax rate on taxable income"
label var treat_i "Treatment"
label var zuzugjahre "Year"

gen Period=(zuzugjahre>=2006)
gen DiD=treat_i*Period

* 2SLS
gen lnnet_avgtt = ln(1-avgtt)
label var lnnet_avgtt "$\eta^F$"
 
ivreg2 Inmovers treat_i  ib2005.zuzugjahre (lnnet_avgtt = DiD) , ffirst redundant(DiD)  robust
weakivtest
		
// REGRESSION TABLE FOR APPENDIX
	outreg2 using "$mypathRR/Results/appendixtables/B5.2_appendixtable.xls", excel label  e(F) dec(3) append ///
	sortvar(DiD lnnet_avgtt treat_i i.zuzugjahre  ) ctitle(" ", "Flow Elasticities", "`x'--`y'\%", "2SLS",) 

restore
drop treat_i

}






* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* 2 TREATMENTS

local b " 60 55"
local t " 80 75"
local n : word count `b'

forvalues i = 1/`n' {
local x : word `i' of `b'
local y : word `i' of `t'
cap drop treat_i
gen treat_i=.
replace treat_i=0 if ctrl_ir_`x'_`y'==1
replace treat_i=1 if taxinc_thre2==1
label var treat_i "Income tax treatment"

preserve
sort persid zuzugjahre year
keep if freq==1
drop if year>2010
drop if zuzugjahre>2010

collapse (count) Inmovers=persid (mean) avgtt=avgt_stek_taxable (mean) avgtg=avgt_stek_gross (mean) mtr=mtr_total (mean) residents , by(zuzugjahre treat_i)
gen weight=Inmovers

xtset treat_i zuzugjahre
tsfill, full
replace Inmovers=0 if Inmovers==.

replace Inmovers=Inmovers/residents*100
label var Inmovers "Share of taxpayers"
label var avgtt "Average tax rate on taxable income"
label var avgtg "Average tax rate on gross income"
label var mtr "Marginal tax rate on taxable income"
label var treat_i "Treatment"
label var zuzugjahre "Year"

gen Period1=0
replace Period1=1 if zuzugjahre>=2006&zuzugjahre<2008
gen DiD1=treat_i*Period1

gen Period2=0
replace Period2=1 if zuzugjahre>=2008
gen DiD2=treat_i*Period2


* 2SLS
gen lnnet_avgtt = ln(1-avgtt)
label var lnnet_avgtt "$\eta^F$"
 
ivreg2 Inmovers treat_i  ib2005.zuzugjahre (lnnet_avgtt = DiD1 DiD2), ffirst redundant(DiD1 DiD2) robust
weakivtest

	outreg2 using "$mypathRR/Results/appendixtables/B5.2_appendixtable.xls", excel label  e(F) dec(3) append ///
	sortvar(DiD lnnet_avgtt treat_i i.zuzugjahre  ) ctitle(" ", " ", "`x'--`y'\%", "2SLS") 

restore
drop treat_i

}





